<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<style type="text/css">
    @font-face {
        font-family: "Ahem";
        src: url(../../../resources/Ahem.ttf);
    }
    body {
        margin:0px;
        border:0px;
        padding:0px;
    }
    text {
        font: 12px Ahem;
    }
    #div2, #svg2 {
        zoom:200%;
    }
    #div3, #svg3 {
        zoom:50%;
    }
</style>
</head>
<body>

<div id="div1" style="width:100px;height:50px;background-color:gray;"></div>
<div id="div2" style="width:100px;height:50px;background-color:green;"></div>
<div id="div3" style="width:200px;height:100px;background-color:blue;"></div>
<div style="width:600px;height=100px;">
<svg id="svg1" xmlns="http://www.w3.org/2000/svg"
     width="150px" height="50px" viewBox="0 0 150 100"
     preserveAspectRatio="none">
  <rect id="rect1" x="0" y="0" width="100px" height="100px" fill="gray" />
  <image id="image1" x="100px" y="0" width="50px" height="50px" xlink:href="../../W3C-SVG-1.1/resources/magnify.png" />
  <text id="text1" x="100px" y="75px">Test</text>
</svg><svg id="svg2" xmlns="http://www.w3.org/2000/svg"
     width="150px" height="50px" viewBox="0 0 150 100"
     preserveAspectRatio="none">
  <rect id="rect2" x="0" y="0" width="100px" height="100px" fill="green" />
  <image id="image2" x="100px" y="0" width="50px" height="50px" xlink:href="../../W3C-SVG-1.1/resources/magnify.png" />
  <text id="text2" x="100px" y="75px">Test</text>
</svg><svg id="svg3" xmlns="http://www.w3.org/2000/svg"
     width="300px" height="100px" viewBox="0 0 150 100"
     preserveAspectRatio="none">
  <rect id="rect3" x="0" y="0" width="100px" height="100px" fill="blue" />
  <image id="image3" x="100px" y="0" width="50px" height="50px" xlink:href="../../W3C-SVG-1.1/resources/magnify.png" />
  <text id="text3" x="100px" y="75px">Test</text>
</svg>
</div>

<div id="description"></div>
<div id="console"></div>

<script>
function executeTest() {
    // 0.02 is slightly larger than one LayoutUnit, which is the biggest allowable difference.
    var tolerance = 0.02;

    description("This test checks getBoundingClientRect() on zoomed HTML and SVG elements");

    debug("Gray rectangles: 100x50");
    debug("Green rectangles: 100x50, zoom=200%");
    debug("Blue rectangles: 200x100, zoom=50%");
    debug("");

    debug("Checking HTML elements:");
    debug("");

    div1 = document.getElementById("div1").getBoundingClientRect();
    shouldBe('div1.left', '0.00', false, tolerance);
    shouldBe('div1.top', '0.00', false, tolerance);
    shouldBe('div1.width', '100.00', false, tolerance);
    shouldBe('div1.height', '50.00', false, tolerance);
    shouldBe('div1.right', '100.00', false, tolerance);
    shouldBe('div1.bottom', '50.00', false, tolerance);
    debug("");

    div2 = document.getElementById("div2").getBoundingClientRect();
    shouldBe('div2.left', '0.00', false, tolerance);
    shouldBe('div2.top', '25.00', false, tolerance);
    shouldBe('div2.width', '100.00', false, tolerance);
    shouldBe('div2.height', '50.00', false, tolerance);
    shouldBe('div2.right', '100.00', false, tolerance);
    shouldBe('div2.bottom', '75.00', false, tolerance);
    debug("");

    div3 = document.getElementById("div3").getBoundingClientRect();
    shouldBe('div3.left', '0.00', false, tolerance);
    shouldBe('div3.top', '300.00', false, tolerance);
    shouldBe('div3.width', '200.00', false, tolerance);
    shouldBe('div3.height', '100.00', false, tolerance);
    shouldBe('div3.right', '200.00', false, tolerance);
    shouldBe('div3.bottom', '400.00', false, tolerance);
    debug("");

    debug("Checking SVG elements:");
    debug("");

    svg1 = document.getElementById("svg1").getBoundingClientRect();
    shouldBe('svg1.left', '0.00', false, tolerance);
    shouldBe('svg1.top', '250.00', false, tolerance);
    shouldBe('svg1.width', '150.00', false, tolerance);
    shouldBe('svg1.height', '50.00', false, tolerance);
    shouldBe('svg1.right', '150.00', false, tolerance);
    shouldBe('svg1.bottom', '300.00', false, tolerance);
    rect1 = document.getElementById("rect1").getBoundingClientRect();
    shouldBe('rect1.left', '0.00', false, tolerance);
    shouldBe('rect1.top', '250.00', false, tolerance);
    shouldBe('rect1.width', '100.00', false, tolerance);
    shouldBe('rect1.height', '50.00', false, tolerance);
    shouldBe('rect1.right', '100.00', false, tolerance);
    shouldBe('rect1.bottom', '300.00', false, tolerance);
    image1 = document.getElementById("image1").getBoundingClientRect();
    shouldBe('image1.left', '100.00', false, tolerance);
    shouldBe('image1.top', '250.00', false, tolerance);
    shouldBe('image1.width', '50.00', false, tolerance);
    shouldBe('image1.height', '25.00', false, tolerance);
    shouldBe('image1.right', '150.00', false, tolerance);
    shouldBe('image1.bottom', '275.00', false, tolerance);
    text1 = document.getElementById("text1").getBoundingClientRect();
    shouldBe('text1.left', '100.00', false, tolerance);
    shouldBe('text1.top', '282.66', false, tolerance);
    shouldBe('text1.width', '47.98', false, tolerance);
    shouldBe('text1.height', '6.16', false, tolerance);
    shouldBe('text1.right', '147.98', false, tolerance);
    shouldBe('text1.bottom', '288.82', false, tolerance);
    debug("");

    svg2 = document.getElementById("svg2").getBoundingClientRect();
    shouldBe('svg2.left', '75.00', false, tolerance);
    shouldBe('svg2.top', '100.00', false, tolerance);
    shouldBe('svg2.width', '150.00', false, tolerance);
    shouldBe('svg2.height', '50.00', false, tolerance);
    shouldBe('svg2.right', '225.00', false, tolerance);
    shouldBe('svg2.bottom', '150.00', false, tolerance);
    rect2 = document.getElementById("rect2").getBoundingClientRect();
    shouldBe('rect2.left', '75.00', false, tolerance);
    shouldBe('rect2.top', '100.00', false, tolerance);
    shouldBe('rect2.width', '100.00', false, tolerance);
    shouldBe('rect2.height', '50.00', false, tolerance);
    shouldBe('rect2.right', '175.00', false, tolerance);
    shouldBe('rect2.bottom', '150.00', false, tolerance);
    image2 = document.getElementById("image2").getBoundingClientRect();
    shouldBe('image2.left', '175.00', false, tolerance);
    shouldBe('image2.top', '100.00', false, tolerance);
    shouldBe('image2.width', '50.00', false, tolerance);
    shouldBe('image2.height', '25.00', false, tolerance);
    shouldBe('image2.right', '225.00', false, tolerance);
    shouldBe('image2.bottom', '125.00', false, tolerance);
    text2 = document.getElementById("text2").getBoundingClientRect();
    shouldBe('text2.left', '175.00', false, tolerance);
    shouldBe('text2.top', '132.66', false, tolerance);
    shouldBe('text2.width', '47.98', false, tolerance);
    shouldBe('text2.height', '6.02', false, tolerance);
    shouldBe('text2.right', '222.98', false, tolerance);
    shouldBe('text2.bottom', '138.70', false, tolerance);
    debug("");

    svg3 = document.getElementById("svg3").getBoundingClientRect();
    shouldBe('svg3.left', '900.00', false, tolerance);
    shouldBe('svg3.top', '500.00', false, tolerance);
    shouldBe('svg3.width', '300.00', false, tolerance);
    shouldBe('svg3.height', '100.00', false, tolerance);
    shouldBe('svg3.right', '1200.00', false, tolerance);
    shouldBe('svg3.bottom', '600.00', false, tolerance);
    rect3 = document.getElementById("rect3").getBoundingClientRect();
    shouldBe('rect3.left', '900.00', false, tolerance);
    shouldBe('rect3.top', '500.00', false, tolerance);
    shouldBe('rect3.width', '200.00', false, tolerance);
    shouldBe('rect3.height', '100.00', false, tolerance);
    shouldBe('rect3.right', '1100.00', false, tolerance);
    shouldBe('rect3.bottom', '600.00', false, tolerance);
    image3 = document.getElementById("image3").getBoundingClientRect();
    shouldBe('image3.left', '1100.00', false, tolerance);
    shouldBe('image3.top', '500.00', false, tolerance);
    shouldBe('image3.width', '100.00', false, tolerance);
    shouldBe('image3.height', '50.00', false, tolerance);
    shouldBe('image3.right', '1200.00', false, tolerance);
    shouldBe('image3.bottom', '550.00', false, tolerance);
    text3 = document.getElementById("text3").getBoundingClientRect();
    shouldBe('text3.left', '1100.00', false, tolerance);
    shouldBe('text3.top', '565.33', false, tolerance);
    shouldBe('text3.width', '95.97', false, tolerance);
    shouldBe('text3.height', '12.31', false, tolerance);
    shouldBe('text3.right', '1195.97', false, tolerance);
    shouldBe('text3.bottom', '577.64', false, tolerance);
    debug("");
}
</script>

<script src="../../../resources/js-test.js"></script>
<script>var zoomCount = 2;</script>
<script src="../../../resources/run-after-layout-and-paint.js"></script>
<script src="../resources/testPageZoom.js"></script>
<script>
if (window.testRunner) {
    window.jsTestIsAsync = true;
    window.postZoomCallback = executeTest;
    document.fonts.ready.then(function() {
      runAfterLayoutAndPaint(repaintTest);
    });
} else {
    debug("This test only works in DRT.");
}
</script>

</body>
</html>
